package com.gem.mapper;

import com.gem.domain.CCooperationResult;
import com.gem.util.ConditionUtil;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Apolar_GuanYH-管阳红
 * Description: 合作成果映射
 * create 2019/10/24 15:10
 * Modified By:
 */
@Mapper
public interface CCooperationResultMapper {

    //查询所有
    List<CCooperationResult> selectAllCR();

    //按编号查询
    @Select("SELECT * FROM c_cooperation_result WHERE cr_id= #{crId} AND cr_status>0")
    CCooperationResult selectCRById(Integer crId);

    //条件查询
    List<CCooperationResult> selectCRByCondition(ConditionUtil cu);

    //添加
    boolean addCR(CCooperationResult cCooperationResult);

    //伪删除
    @Update("UPDATE c_cooperation_result SET cr_status=-1 WHERE cr_id=#{crId}")
    boolean deleteCRById(Integer crId);

    //修改
    boolean modifyCR(CCooperationResult cCooperationResult);

    //查询所有其他合作成果
    @Select("select * from c_cooperation_result where cr_type = '其他' and cr_id in (select c.cc_cr_id from c_cr_company c where c.cc_company_id = #{coId})  and cr_status > 0")
    List<CCooperationResult> findOther(@Param("coId") int coId);

    //添加合作成果
    Integer saveOther(CCooperationResult result);

    //添加中间表
    Integer saveCother(@Param("crId") Integer crId, @Param("coId") Integer coId);

    //删除其他合作成果
    @Update("update c_cooperation_result set cr_status = -1 where cr_id = #{crId}")
    Integer deleteOtherById(Integer crId);

    //删除中间表
    @Delete("update c_cr_company set cc_status = -1 where cc_cr_id = #{crId}")
    Integer deleteCother(@Param("crId") Integer crId);

    //根据id查询其他合作成果
    @Select("select * from c_cooperation_result where cr_id =#{crId} and cr_status>0")
    CCooperationResult findOtherById(Integer crId);

    //根据id修改其他合作成果
    @Update("update c_cooperation_result set cr_remark = #{crRemark} where cr_id = #{crId}")
    Integer updateOtherById(CCooperationResult result);

    //删除所选其他合作成果
    Integer deleteAllOther(int[] crIds);

    //删除所选中间表
    Integer deleteAllCother(int[] crIds);
}